package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.ADataInfo;
import com.ruoyi.system.domain.AUser;
import com.ruoyi.system.domain.vo.HgACheckInforVO;
import com.ruoyi.system.domain.vo.XcxACheckInforVO;
import com.ruoyi.system.mapper.AUserMapper;
import com.ruoyi.system.util.LoginUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ACheckInforMapper;
import com.ruoyi.system.domain.ACheckInfor;
import com.ruoyi.system.service.IACheckInforService;

/**
 * 打卡详细Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-29
 */
@Service
public class ACheckInforServiceImpl implements IACheckInforService 
{
    @Autowired
    private ACheckInforMapper aCheckInforMapper;

    @Autowired
    private AUserMapper aUserMapper;


    /**
     * 查询打卡详细
     * 
     * @param id 打卡详细主键
     * @return 打卡详细
     */
    @Override
    public ACheckInfor selectACheckInforById(Long id)
    {
        return aCheckInforMapper.selectACheckInforById(id);
    }

    /**
     * 查询打卡详细列表
     * 
     * @param hgACheckInforVO 打卡详细
     * @return 打卡详细
     */
    @Override
    public List<HgACheckInforVO> selectACheckInforList(HgACheckInforVO hgACheckInforVO)
    {
        return aCheckInforMapper.selectACheckInforList(hgACheckInforVO);
    }

    /**
     * 新增打卡详细
     * 
     * @param aCheckInfor 打卡详细
     * @return 结果
     */
    @Override
    public int insertACheckInfor(ACheckInfor aCheckInfor)
    {
        aCheckInfor.setCreateTime(DateUtils.getNowDate());
        if (aCheckInfor.getIsState() == null){
            aCheckInfor.setIsState("0");
        }
        return aCheckInforMapper.insertACheckInfor(aCheckInfor);
    }

    /**
     * 修改打卡详细
     * 
     * @param aCheckInfor 打卡详细
     * @return 结果
     */
    @Override
    public int updateACheckInfor(ACheckInfor aCheckInfor)
    {
        aCheckInfor.setUpdateTime(DateUtils.getNowDate());
        return aCheckInforMapper.updateACheckInfor(aCheckInfor);
    }

    /**
     * 批量删除打卡详细
     * 
     * @param ids 需要删除的打卡详细主键
     * @return 结果
     */
    @Override
    public int deleteACheckInforByIds(Long[] ids)
    {
        return aCheckInforMapper.deleteACheckInforByIds(ids);
    }

    /**
     * 删除打卡详细信息
     * 
     * @param id 打卡详细主键
     * @return 结果
     */
    @Override
    public int deleteACheckInforById(Long id)
    {
        return aCheckInforMapper.deleteACheckInforById(id);
    }

    @Override
    public List<HgACheckInforVO> selectACheckInforXcxList(HgACheckInforVO hgACheckInforVO) {
        AUser au = aUserMapper.selectAUserById(LoginUtils.getUser().getId());
        hgACheckInforVO.setAgentLevel(au.getRole());
        List<HgACheckInforVO> list = aCheckInforMapper.selectACheckInforXcxList(hgACheckInforVO);
        if(!list.isEmpty()){
            for (HgACheckInforVO aCheckInforVO : list) {
                String[] str = aCheckInforVO.getInfoImage().split(",");
                aCheckInforVO.setListImg(Arrays.asList(str));
            }
        }
        return list;
    }

    @Override
    public int insertAXcxCheckInfor(ACheckInfor aCheckInfor) {
        aCheckInfor.setIsState("0");
        aCheckInfor.setCreateTime(DateUtils.getNowDate());
        aCheckInfor.setCreateBy(LoginUtils.getUser().getId().toString());
        return aCheckInforMapper.insertACheckInfor(aCheckInfor);
    }

    @Override
    public XcxACheckInforVO selectACheckInforByXcxId(Long id) {
        Long userId = LoginUtils.getUser().getId();
        XcxACheckInforVO vo = aCheckInforMapper.selectACheckInforByXcxId(id,userId);
        String[] str = vo.getInfoImage().split(",");
        List<String> arr = new ArrayList<String>();
        for (String s : str){
            arr.add(s);
        }
        vo.setListImg(arr);
        return vo;
    }
}
